#!/bin/bash
##获取当前系统的类型
##获取Debian系统的版本信息
get_os_info_os__Debian_OS_Version(){
    unset System_version
    System_version=`grep VERSION_ID /etc/os-release  | sed -e 's/VERSION_ID=//' -e 's/\"//g'`
    unset source_version
    ##获取系统代号
    eval `grep VERSION_CODENAME /etc/os-release`
}
##获取CentOS系统的版本信息
get_os_info_os__Centos_OS_Version(){
    unset System_version
    System_version=`cat /etc/os-release  | grep VERSION_ID | sed -e 's/VERSION_ID=//' -e 's/\"//g'`
    source_version="$System_version"
}
get_os_info_os__Type(){
    System_Type=`cat /etc/os-release  | grep ^ID= | sed -e 's/ID=//' -e 's/\"//g'`
    if [[ "${System_Type}" == "$type" ]];then
        os_check='y'
    fi
    if [[ "$local_install" -eq 'rpm' ]];then
        get_os_info_os__Centos_OS_Version
    elif [[ "$local_install" -eq 'dpkg'  ]];then
        get_os_info_os__Debian_OS_Version
    fi
    if [[ "$os_check" -eq 'y' ]];then
        red_z_green_z "当前系统类型" "支持"
    else
        red_zt_bg "当前系统类型" "不支持"
        exit 11
    fi
}
get_os_info_os-Package-management(){
    if [[ -f '/usr/bin/apt' ]];then
        local_install='dpkg'
        Package_management='apt'
        Package_managements='apt'
        local_search="apt list --installed "
    elif [[ -f '/usr/bin/yum' ]];then
        yum --version > /dev/null
        if [[ "$?" -eq '0' ]];then
            Package_management='yum'
            Package_managements='yum'
            if [[ -f '/usr/bin/dnf' ]];then
                dnf --version > /dev/null
                if [[ "$?" -eq '0' ]];then
                    Package_management='dnf'
                fi
            fi
            local_search='rpm -qa '
        else
            red_zt_bg "包管理器[ yum ]" "出现意外"
            exit 11
        fi
        local_install='rpm'
    else
        red_zt_bg "无法判断当前系统使用的包管理器"
        exit 11
    fi
    export install="${Package_management} install -y"
    export unstall="${Package_management} remove -y"
}
